<?php

function genLink()
{
    $today = date('md');
    $filename = 'malllink/' . $today . '.txt';
    $mall='';
    if (!file_exists($filename))
    {
        $mall = file_get_contents('http://xiazaiquan.com/mall/forum.html');
        $mall = trim($mall);
        if ($mall != '')
        {
            file_put_contents($filename, $mall);
        }
        else
        {
            $list = scandir('malllink');
            $list = array_diff($list, array('.', '..'));
            $file = 'malllink/' . $list[array_rand($list)];
            $mall = file_get_contents($file);
        }
    }
    else
    {
        $list = scandir('malllink');
        $list = array_diff($list, array('.', '..'));
        $file = 'malllink/' . $list[array_rand($list)];
        $mall = file_get_contents($file);
    }
    return $mall;
}

$link = genLink();
$link = trim($link);
if ($link == '')
{
    $link = genLink();
}
echo $link;
?>